
#include "AUEffectBase.h"
#include "AUEffectBase.h"
#include "OctogrisVersion.h"
#include "CommonSettings.h"
#include "AUEffectBase.h"

#if AU_DEBUG_DISPATCHER
	#include "AUDebugDispatcher.h"
#endif


#ifndef __Octogris_h__
#define __Octogris_h__

template<int mNumberOfSources, int mNumberOfSpeakers>
class Octogris : public AUEffectBase
{
public:
	Octogris(AudioUnit component);
	virtual ~Octogris();
	
	virtual	OSStatus			GetParameterValueStrings(AudioUnitScope			inScope,
														 AudioUnitParameterID		inParameterID,
														 CFArrayRef *			outStrings);
    
	virtual	OSStatus			GetParameterInfo(AudioUnitScope			inScope,
												 AudioUnitParameterID	inParameterID,
												 AudioUnitParameterInfo	&outParameterInfo);
    
	virtual OSStatus			GetPropertyInfo(AudioUnitPropertyID		inID,
												AudioUnitScope			inScope,
												AudioUnitElement		inElement,
												UInt32 &			outDataSize,
												Boolean	&			outWritable );
	
	virtual OSStatus			GetProperty(AudioUnitPropertyID inID,
											AudioUnitScope 		inScope,
											AudioUnitElement 		inElement,
											void *			outData);
											
	virtual OSStatus			SetProperty(AudioUnitPropertyID 		inID,
											AudioUnitScope 				inScope,
											AudioUnitElement 			inElement,
											const void *				inData,
											UInt32 						inDataSize);
											
	virtual void				PostConstructor();
	virtual UInt32				SupportedNumChannels (const AUChannelInfo** outInfo);
	
 	virtual	bool				SupportsTail () { return true; }
	virtual Float64				GetTailTime()	{ return 0; }
	
	virtual OSStatus			Version() { return kOctogrisVersion; }
	
	virtual OSStatus ProcessBufferLists(AudioUnitRenderActionFlags & ioActionFlags, 
												const AudioBufferList & oInBuffer,
												AudioBufferList & outBuffer, 
												UInt32 inFramesToProcess);
	
	virtual OSStatus			Reset(	AudioUnitScope 		inScope,
										AudioUnitElement 	inElement);

	virtual void ProcessData(float **inputs, float **outputs, float *params, float sampleRate, UInt32 frames);
	
private:
	AUChannelInfo mChannelInfo;

	bool mCalculateLevels;
	float mLevels[mNumberOfSpeakers];
	
	bool mSmoothedParametersInited;
	float mSmoothedParameters[mNumberOfParameters];
	
	float mInputsCopy[mNumberOfSources][1024];
	float mSmoothedParametersRamps[mNumberOfParameters][1024];
	
	int64 mProcessCounter;
};

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


#endif